import { Point } from "..";
import { Shape } from "./shape";

export class Polygon extends Shape {
  protected _points: Point[];

  constructor() {
    super(0, 0, "blue", "white");
    this._points = [];
  }

  addPoint(x: number, y: number) {
    this._points.push({ x, y });
  }

  createPath(ctx: CanvasRenderingContext2D): void {
    if (this._points.length < 1) return;
    ctx.beginPath();
    ctx.moveTo(this._points[0].x, this._points[0].y);
    for (let i = 1; i < this._points.length; ++i) {
      ctx.lineTo(this._points[i].x, this._points[i].y);
    }
    ctx.closePath();
  }
}
